package com.example.arithmeticleetcode.leetcode.July;

import java.util.Arrays;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-07-06 10:00
 **/
public class Demo03 {

    public static void main(String[] args) {
        int[] arr0 = {3, 5, 1};
        System.out.println(canMakeArithmeticProgression(arr0)); //true
        int[] arr1 = {1, 2, 4};
        System.out.println(canMakeArithmeticProgression(arr1)); //false
    }


    public static boolean canMakeArithmeticProgression(int[] arr) {
        Arrays.sort(arr);
        int value = arr[1] - arr[0];
        for (int i = 1, len = arr.length - 1; i < len; i++) {
            if (arr[i + 1] - arr[i] != value) {
                return false;
            }
        }
        return true;
    }

}
